#ifndef DIRECTIONCTL_H
#define DIRECTIONCTL_H

#include <QPushButton>
#include <QTimer>
#include <QWidget>

#include "node/node.h"

class DirectionCtl : public QWidget {
    Q_OBJECT

  public:
    explicit DirectionCtl(QPushButton *btnFront, QPushButton *btnBack, QPushButton *btnLeft, QPushButton *btnRight,
                          std::shared_ptr<AppNode> appNode, QWidget *parent = nullptr);
    ~DirectionCtl();

    void btnFrontPressed(bool isPressed);
    void btnBackPressed(bool isPressed);
    void btnLeftPressed(bool isPressed);
    void btnRightPressed(bool isPressed);

  private slots:
    void onTimeout();

  private:
    void startTimer();
    void stopTimer();

  private:
    QPushButton *btnFront_;
    QPushButton *btnBack_;
    QPushButton *btnLeft_;
    QPushButton *btnRight_;

    bool btnFrontPressed_;
    bool btnBackPressed_;
    bool btnLeftPressed_;
    bool btnRightPressed_;

    std::shared_ptr<AppNode> appNode_;

    QTimer timer_;
};

#endif // DIRECTIONCTL_H
